<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Pow(x,n)</title>
</head>
<body>
  <script>
    function fn(x, n) {
      let ans = n < 0, res = 1;
      n = Math.abs(n);
      for (let i = 0; i < n; i++) {
        res *= x;
      }
      return ans ? 1 / res : res;
    }
    console.log(fn(2.00000, -1));
  </script>
</body>
</html>